package org.dandang.bookcorner.bookcorner;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ClassManageHomeActivity extends AppCompatActivity implements View.OnClickListener {
    private GridView gv_class_student;
    private List<Map<String, Object>> dataList;
    private SimpleAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_class_manage);

        initData();
        init();
    }

    private void init() {

        gv_class_student = findViewById(R.id.gv_class_student);
        String[] from={"stu_no","stu_name"};
        int[] to={R.id.stu_no,R.id.stu_name};
        adapter = new SimpleAdapter(this, dataList, R.layout.activity_class_manage_item, from, to);
        gv_class_student.setAdapter(adapter);

        gv_class_student.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //AlertDialog.Builder builder= new AlertDialog.Builder(ClassManageHomeActivity.this);
                //builder.setTitle("提示").setMessage(dataList.get(arg2).get("text").toString()).create().show();
                Intent intent = new Intent(ClassManageHomeActivity.this,StudentHomeActivity.class);
                startActivity(intent);
            }
        });

        Button btn_manage = findViewById(R.id.btn_manage);
        btn_manage.setOnClickListener(this);
    }

    void initData() {
        //学生编号
        String stu_no[] = {"01","02","03","04","05","06","07","08","09","10","11","12",
                "01","02","03","04","05","06","07","08","09","10","11","12",
                "01","02","03","04","05","06","07","08","09","10","11","12"};
        //学生姓名
        String name[]={"时钟","信号","宝箱","秒钟","大象","FF","记事本","书签","印象","商店","主题","迅雷",
                "时钟","信号","宝箱","秒钟","大象","FF","记事本","书签","印象","商店","主题","迅雷",
                "时钟","信号","宝箱","秒钟","大象","FF","记事本","书签","印象","商店","主题","迅雷"};
        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i <stu_no.length; i++) {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("stu_no", stu_no[i]);
            map.put("stu_name",name[i]);
            dataList.add(map);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_manage:
                Intent intent = new Intent(this,ClassManageActivity.class);
                startActivity(intent);
                break;
        }
    }
}
